/*
 * @lc app=leetcode.cn id=53 lang=javascript
 *
 * [53] 最大子序和
 */

// @lc code=start
/**
 * @param {number[]} nums
 * @return {number}
 */
var maxSubArray = function(nums) {
  let sum = 0
  let max = nums[0]
  while (nums.length > 0) {
    sum = sum < 0 ? 0 : sum
    sum += nums.shift()
    max = Math.max(max, sum)
  }
  return max
}
// @lc code=end

